﻿using System.Net;
using RSSFeedReader.Data.Models;

namespace RSSFeedReader.ViewModels
{
    /// <summary>
    /// View Model only exposes the options
    /// for the application.
    /// </summary>
    public class ManageFeedsViewModel : ManageChannelBaseViewModel
    {
        #region Constructor
        /// <summary>
        /// Initialize a new instance of the OptionsViewModel class.
        /// </summary>
        public ManageFeedsViewModel()
        {
            RefreshPeriod = ChannelDataSource.Instance.RefreshPeriod;
            ProxySetting = new ProxySetting
            {
                Address = ChannelDataSource.Instance.ProxySetting.Address,
                Domain = ChannelDataSource.Instance.ProxySetting.Domain,
                Password = ChannelDataSource.Instance.ProxySetting.Password,
                Port = ChannelDataSource.Instance.ProxySetting.Port,
                UserName = ChannelDataSource.Instance.ProxySetting.UserName
            };
            SaveChanges = false;
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// Gets or sets the refresh period for the application.
        /// </summary>
        public int RefreshPeriod { get; set; }

        /// <summary>
        /// Gets a value indicating if changes should be saved or not.
        /// </summary>
        public bool SaveChanges { get; private set; }

        /// <summary>
        /// Gets or sets the proxy settings for the application.
        /// </summary>
        public ProxySetting ProxySetting { get; set; }
        #endregion

        #region Override Methods
        /// <summary>
        /// Overrides the DoOKCommand.
        /// </summary>
        public override void DoOKCommand()
        {
            ChannelDataSource.Instance.RefreshPeriod = RefreshPeriod;
            ChannelDataSource.Instance.ProxySetting = ProxySetting;
            SaveChanges = true;
            base.DoOKCommand();
        }
        #endregion
    }
}
